package com.example.batalhanaval;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PlayerListAdapter extends BaseAdapter {

	private Context context;
	private List<Player> lista;

	public PlayerListAdapter(Context ctx, List<Player> players)
	{
		context = ctx;
		lista = players;

	}


	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lista.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return lista.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return lista.get(arg0).getId();
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup parent) 
	{
		ViewHolder holder;
		Player player = lista.get(pos);

		if (convertView == null)
		{
			convertView = LayoutInflater.from(context).inflate(R.layout.activity_lista, null);
			
			holder = new ViewHolder();
			holder.txtNome = (TextView)convertView.findViewById(R.id.nome);
			holder.txtPontuacao = (TextView)convertView.findViewById(R.id.pontuacao);
			convertView.setTag(holder);
			
		}
		else
		{
			holder = (ViewHolder)convertView.getTag();
		}
		
		holder.txtNome.setText(player.getNome());
		holder.txtPontuacao.setText(player.getPontuacao());
		
		return convertView;
	}

	static class ViewHolder
	{
		TextView txtNome;
		TextView txtPontuacao;		
	}

}
